﻿' LibWowArmory
' by Ronald M. Clifford (roncli@roncli.com)
'
' This source code is released under the GNU Library General Public License (LGPL) Version 2.1.

Imports System.Text.RegularExpressions

Namespace roncliProductions.LibWowArmory.Character.Achievements

    ''' <summary>
    ''' A class that encapsulates achievement criteria information
    ''' </summary>
    ''' <remarks></remarks>
    Public Class AchievementCriteria

        ''' <summary>
        ''' The date this criteria was completed
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks>This is only important if the achievement itself has not been earned yet.  If the achievement was completed, most of the time this field will be Date.MinValue, but sometimes it may have data in it.</remarks>
        Public Property [Date] As Date

        ''' <summary>
        ''' The identification number of the achievement's criteria
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property CriteriaID As Integer

        ''' <summary>
        ''' The number items or repititions required to fulfill this criteria
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property MaxQuantity As Integer

        ''' <summary>
        ''' The amount of copper required to fulfill this criteria
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property MaxQuantityCurrency As Integer

        ''' <summary>
        ''' The display name of the achievement's criteria
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Name As String

        ''' <summary>
        ''' The current number of items or repetitions earned for this criteria
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Quantity As Integer

        ''' <summary>
        ''' The current amount of copper earned for this criteria
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property QuantityCurrency As Integer

        ''' <summary>
        ''' A constructor to create new achievement criteria information
        ''' </summary>
        ''' <param name="strDate"></param>
        ''' <param name="intID"></param>
        ''' <param name="intMaxQuantity"></param>
        ''' <param name="intMaxQuantityCurrency"></param>
        ''' <param name="strName"></param>
        ''' <param name="intQuantity"></param>
        ''' <param name="intQuantityCurrency"></param>
        ''' <remarks></remarks>
        Public Sub New(ByVal strDate As String, ByVal intID As Integer, ByVal intMaxQuantity As Integer, ByVal intMaxQuantityCurrency As Integer, ByVal strName As String, ByVal intQuantity As Integer, ByVal intQuantityCurrency As Integer)
            [Date] = DatestampToDate(strDate)
            CriteriaID = intID
            MaxQuantity = intMaxQuantity
            MaxQuantityCurrency = intMaxQuantityCurrency
            Name = strName
            Quantity = intQuantity
            QuantityCurrency = intQuantityCurrency
        End Sub

        Private Shared strDatestampExpression As String = "((?:2|1)\d{3}(?:-|\/)(?:(?:0[1-9])|(?:1[0-2]))(?:-|\/)(?:(?:0[1-9])|(?:[1-2][0-9])|(?:3[0-1])))([+-])?((?:(?:[0-1][0-9])|(?:[2][0-3]))):((?:[0-5][0-9]))"
        Private Shared Function DatestampToDate(ByVal strDate As String) As Date
            If String.IsNullOrEmpty(strDate) Then Return Date.MinValue
            Dim mcMatch As MatchCollection = Regex.Matches(strDate, strDatestampExpression)
            If mcMatch.Count = 0 Then
                Return Date.MinValue
            End If
            Return CDate(mcMatch(0).Groups(1).Value)
        End Function

    End Class

End Namespace
